//
//  HiLikeCell.m
//  HiCar
//
//  Created by huachun on 2019/1/3.
//  Copyright © 2019 丁一. All rights reserved.
//

#import "HiLikeCell.h"
#import "HiJonesClass.h"
#import "OSSTestMacros.h"

@interface HiLikeCell ()

@property (nonatomic, strong) UIImageView *User_logo;
@property (nonatomic, strong) UILabel     *User_name;
@property (nonatomic, strong) UIButton    *User_sex;

@end

@implementation HiLikeCell

+ (instancetype)cellForTableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *ID = @"HiLikeCell";
    HiLikeCell  *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell){
        cell=[[HiLikeCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
        cell.backgroundColor=[UIColor whiteColor];
        tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
        cell.accessoryType=UITableViewCellAccessoryNone;
        
        [cell.contentView addSubview:cell.User_logo];
        [cell.contentView addSubview:cell.User_name];
        [cell.contentView addSubview:cell.User_sex];
        
        [cell.contentView.layer addSublayer:cell.new_line];
    }
    
    return cell;
}

- (void)setModel:(UserModel *)Model{
    if (_Model != Model) {
        _Model = Model;
    }
    [_User_logo sd_setImageWithURL:[NSURL URLWithString:_Model.logo] placeholderImage:[UIImage imageNamed:@"usermoren.png"]];
    _User_name.text=_Model.name;
    
    if ([_Model.sex isEqualToString:@"False"]) {
        _User_sex.backgroundColor=Bluecolor;
        [_User_sex setImage:[UIImage imageNamed:@"sex_nan"] forState:UIControlStateNormal];
    }else{
        _User_sex.backgroundColor=Fengcolor;
        [_User_sex setImage:[UIImage imageNamed:@"sex_nv"] forState:UIControlStateNormal];
    }
    [_User_sex setTitle:[NSString stringWithFormat:@" %li",(long)[HiJonesClass ageWithDateOfBirth:_Model.briday]] forState:UIControlStateNormal];
_new_line.hidden = YES;
}

-(UIImageView *)User_logo{
    if (!_User_logo) {
        _User_logo                     = [[UIImageView alloc] initWithFrame:CGRectMake(15, 15, 50, 50)];
        _User_logo.layer.masksToBounds = YES;
        _User_logo.layer.cornerRadius  = 25;
        _User_logo.contentMode         = UIViewContentModeScaleAspectFill;
    }
    return _User_logo;
}

-(UILabel *)User_name{
    if (!_User_name) {
        _User_name = [[UILabel alloc] initWithFrame:CGRectMake(70, 15, RECRWITCH-80, 25)];
        [_User_name setFont:[UIFont boldSystemFontOfSize:15]];
        [_User_name setTextColor:[JonesClass stringTOColor:@"#222222"]];
    }
    return _User_name;
}

- (UIButton *)User_sex {
    if (!_User_sex) {
        _User_sex = [[UIButton alloc] initWithFrame:CGRectMake(70, 45, 45, 16)];
        [_User_sex setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _User_sex.titleLabel.font=[UIFont boldSystemFontOfSize:11];
        _User_sex.backgroundColor=[JonesClass stringTOColor:@"#ee5eb2"];
        _User_sex.layer.cornerRadius=8;
    }
    return _User_sex;
}

- (CALayer *)new_line{
    if (!_new_line) {
        _new_line = [CALayer new];
        _new_line.backgroundColor = [UIColor redColor].CGColor;
        _new_line.frame=CGRectMake(RECRWITCH-18, 10, 8, 8);
        _new_line.cornerRadius = 4;
        _new_line.masksToBounds = YES;
    }
    return _new_line;
}

@end
